<template>
    <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="85px">
      <el-form-item label="" prop="settlement">
        <el-radio-group v-model="queryParams.settlement" @change="handleQuery">
          <el-radio-button label="1">已结算</el-radio-button>
          <el-radio-button label="2">未结算</el-radio-button>
        </el-radio-group>
      </el-form-item>
    </el-form>
  </ContentWrap>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="用户头像" align="center" prop="id" />
      <el-table-column label="用户名称" align="center" prop="id" />
      <el-table-column label="获得佣金" align="center" prop="walletId" />
      <el-table-column label="缴费类型" align="center" prop="title" />
      <el-table-column label="缴费时间" align="center" prop="title" />
      <el-table-column label="到期时间" align="center" prop="createTime" :formatter="dateFormatter" width="180px" />
    </el-table>
    <!-- 分页 -->
    <Pagination :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </ContentWrap>
</template>

<script lang="ts" setup>
import { dateFormatter } from '@/utils/formatTime'
import * as WalletTransactionApi from '@/api/pay/wallet/transaction'
import { fenToYuan } from '@/utils'

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  name: null,
  createTime: [],
  userId: NaN
})

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await WalletTransactionApi.getWalletTransactionPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

const { userId } = defineProps({
  userId: {
    type: Number,
    required: true
  }
})

/** 初始化 **/
onMounted(() => {
  queryParams.userId = userId
  getList()
})
</script>
